// const baseUrl = 'http://dating.servicegarden.cn/';
const baseUrl = 'http://dating.servicegarden.cn/';

// 封装fetch请求函数
function request(url, {
    type = 'post',
    data = {},
    headers = {},
} = options) {
    return new Promise((resolove, reject) => {
        url = baseUrl + url;
        const requestOptions = {
            headers: {
                'Accept': 'application/json, text/plain, */*',
                'Content-Type': 'application/json;charset=UTF-8',
                cookie: document.cookie,
                ...headers
            },
            type,
            dataType: 'json',
        };
        if (type.toUpperCase() === 'POST') {
            requestOptions.data = JSON.stringify(data);
        } else if (type.toUpperCase() === 'GET') {
            const params = new URLSearchParams(Object.entries(data));
            url += `?${params.toString()}`;
        }
        $.ajax({
            url, ...requestOptions,
            success: function (response) {
                resolove(response)
            },
            error: function (err) {
                reject(err)
            }
        })
    })


}